package com.t114514.demo.controller;
import com.github.pagehelper.Page;
import com.t114514.demo.pojo.Course;
import com.t114514.demo.pojo.PageBean;
import com.t114514.demo.pojo.Result;
import com.t114514.demo.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @RequestMapping("/getCourse")
    public Result<PageBean<Course>> getCourse(int pageNum, int pageSize){
        PageBean<Course> c = courseService.getCourse(pageNum,pageSize);
        return Result.success(c);
    }

    // 添加课程
    @PostMapping("/addCourse")
    public Result<String> addCourse(@RequestBody Course course) {
        courseService.addCourse(course);
        return Result.success("添加课程成功");
    }

    // 删除课程（使用POST请求）
    @PostMapping("/deleteCourse")
    public Result<String> deleteCourse(@RequestParam Integer courseId) {
        courseService.deleteCourse(courseId);
        return Result.success("删除课程成功");
    }
}
